package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Date;

/**
 * @Author :冉佳
 * @CreateTime: 2025-02-10
 * @Description:
 * @Version:1.0
 **/
// 定时任务类  处理定时任务
@Component
public class ScheduleTasks {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    // 检查租约是过期
//    @Scheduled(cron = "* * * * * *")
    public void checkAggrementIsExpired(){



        leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>().
                le(LeaseAgreement::getLeaseEndDate,new Date()).
                in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING).
                set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED));
        System.out.println(LocalDate.now());
    }
}
